package cn.bgs.controller;


import cn.bgs.common.R;
import cn.bgs.pojo.MonthCard;
import cn.bgs.service.IMonthCardService;
import cn.bgs.service.impl.MonthCardServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import cn.bgs.common.R;
import cn.bgs.pageUtil.MybatisPageHelper;
import cn.bgs.pageUtil.PageRequest;
import cn.bgs.pageUtil.PageResult;
import cn.bgs.service.IMonthCardService;
import cn.bgs.vo.MonthVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 月卡表 前端控制器
 * </p>
 *
 * @author cf
 * @since 2022-06-07
 */
@RestController
@RequestMapping("/month-card")
public class MonthCardController {
    @Autowired
    IMonthCardService iMonthCardService;
    //查询月卡信息

    @RequestMapping("/selectPcInfo")
    public R selectPcInfo(@RequestBody MonthVo monthVo) {
        return iMonthCardService.selectPcInfo(monthVo);
    }
//    @RequestMapping("/selectPcInfo")
////    public R selectPcInfo(PageRequest pageRequest){
////        MybatisPageHelper.startPage(pageRequest);
////        List<MonthVo> list=iMonthCardService.selectPcInfo();
////        PageResult pageResult = MybatisPageHelper.getPageResult(list);
////        return R.ok().data("list",pageResult);
////    }


    //修改月卡信息
    @PostMapping("/updateYkinfo")
    public R updateYkinfo(@RequestBody MonthVo monthVo){
        if (iMonthCardService.updateYkinfo(monthVo)){
            return R.ok();
        }
        return R.error();
    }
    //添加月卡信息
    @PostMapping("/addYkInfo")
    public R addYkInfo(@RequestBody MonthVo monthVo){
        boolean a = iMonthCardService.addYkInfo(monthVo);
        return R.ok().data("data", a);
    }
    //删除月卡信息
    @GetMapping("/delYkInfo")
    public R delYkInfo(Integer cardId){
        return iMonthCardService.delYkInfo(cardId);
    }

    @Autowired
    private IMonthCardService monthCardService;

    @PostMapping("/buyMonthCard")
    public R buyMonthcard(@RequestBody MonthCard monthCard){
        String s = monthCard.toString();
        System.out.println(s+"==");
        int ins = monthCardService.buyMonthCard(monthCard);
        if(ins == 1){
            return R.ok();
        }else{
            return R.error();
        }

    }

}
